package cn.jbt.api.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.jbt.api.admin.annotation.Log;
import cn.jbt.api.admin.entity.SysDept;
import cn.jbt.api.admin.service.ISysDeptService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system/dept")
@Slf4j
@AllArgsConstructor
public class SysDeptController {

    private final ISysDeptService iSysDeptService;

    @PostMapping("/list")
    @SaCheckPermission("system:dept:list")
    @Log(bizType = "查询", bizName = "查询部门信息列表")
    public List<SysDept> getAll(@RequestBody SysDept sysDept) {
        return iSysDeptService.getAll(sysDept);
    }

    @PostMapping("/add")
    @SaCheckPermission("system:dept:add")
    @Log(bizType = "新增", bizName = "新增部门信息")
    public SysDept add(@Valid @RequestBody SysDept sysDept) {
        return iSysDeptService.add(sysDept);
    }

    @PostMapping("/edit")
    @SaCheckPermission("system:dept:edit")
    @Log(bizType = "编辑", bizName = "编辑部门信息")
    public SysDept edit(@Valid @RequestBody SysDept sysDept) {
        return iSysDeptService.edit(sysDept);
    }

    @PostMapping("/del")
    @SaCheckPermission("system:dept:del")
    @Log(bizType = "删除", bizName = "删除部门信息")
    public void del(@NotEmpty @RequestBody List<Long> ids) {
        iSysDeptService.del(ids);
    }

}
